package com.fang.system.io.mocknetty;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description TODO
 * @date 2022/7/15 2:46 下午
 **/
public class EventLoopGroup {
    AtomicInteger atomic = new AtomicInteger(0);
    EventLoop[] eventLoops;

    public EventLoopGroup(int threadNum) {
        eventLoops = new EventLoop[threadNum];
        for (int i = 0; i < threadNum; i++) {
            eventLoops[i] = new EventLoop("T-" + i);
        }
    }

    public EventLoop chooser() {
        return eventLoops[atomic.getAndIncrement() % eventLoops.length];
    }
}
